package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.po.Address;
import com.atguigu.crowd.entity.po.AddressExample;
import com.atguigu.crowd.entity.vo.AddressVO;
import com.atguigu.crowd.entity.vo.OrderProjectVO;
import com.atguigu.crowd.mapper.AddressMapper;
import com.atguigu.crowd.mapper.OrderPOMapper;
import com.atguigu.crowd.mapper.OrderProjectMapper;
import com.atguigu.crowd.service.api.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zzqstart
 * @Description
 * @date 2022-09-25 14:24
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderPOMapper orderPOMapper;
    @Autowired
    private OrderProjectMapper orderProjectMapper;
    @Autowired
    private AddressMapper addressMapper;

    @Override
    public OrderProjectVO getOrderProjectVO(String projectId, String returnId) {
        return orderProjectMapper.selectOrderProjectVO(returnId);
    }

    @Override
    public List<AddressVO> getAddressVOList(Integer memberId) {
        AddressExample addressExample = new AddressExample();
        addressExample.createCriteria().andMemberIdEqualTo(memberId);
        List<Address> addressList= addressMapper.selectByExample(addressExample);
        List<AddressVO> addressVOList = new ArrayList<>();
        for (Address address : addressList) {
            AddressVO addressVO = new AddressVO();
            BeanUtils.copyProperties(address,addressVO);
            addressVOList.add(addressVO);
        }
        return addressVOList;
    }

    @Override
    public void saveAddress(AddressVO addressVO) {
        Address address = new Address();
        BeanUtils.copyProperties(addressVO,address);
        addressMapper.insertSelective(address);
    }
}
